package com.cn.sx;

import java.util.LinkedList;
import java.util.List;

public class TestSplit {
	public void split(String source){
		int startIndex=0,endIndex=0;
		boolean inQuote=false;
		List<String> result=new LinkedList<String>();
		for(int i=0;i<source.length();i++){
			Character x=source.charAt(i);
			if(x.equals(',')){
				if(!inQuote){
					endIndex=i;
					result.add(source.substring(startIndex, endIndex));
					startIndex=i+1;
				}
			}
			if(x.equals('\"')){
				inQuote=!inQuote;
			}
			if(i==source.length()-1){
				result.add(source.substring(startIndex, source.length()));
			}
		}
		for(String r:result){
			System.out.println(r);
		}
	}//1,"a,b"
	public static void main(String[] args) {
		new TestSplit().split("1,\"a,b\",6,09");
	}
}
